//
//  XHPathTimeScroller.m
//  XHPathTimeScroller
//
//  Created by 曾 宪华 on 14-1-18.
//  Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群（142557668）. All rights reserved.
//

#import "XHPathTimeScroller.h"

#define XHScreenMainBounds [[UIScreen mainScreen] bounds]

@interface XHPathTimeScroller () {
    
    __weak UITableView *_tableView;
    __weak UIImageView *_scrollBar;
    
    UILabel *_timeLabel;
    UILabel *_dateLabel;
    UIImageView *_backgroundImageView;
    
    UIView *_handContainer;
    UIView *_hourHand;
    UIView *_minuteHand;
    
    UIImage *_timeScrollBackgroundImage;
    UIImage *_hourHandImage;
    UIImage *_minuteHandImage;
    
    NSDate *_lastDate;
    CGSize _savedTableViewSize;
}

@property (nonatomic, copy) NSDateFormatter *timeDateFormatter;
@property (nonatomic, copy) NSDateFormatter *dayOfWeekDateFormatter;
@property (nonatomic, copy) NSDateFormatter *monthDayDateFormatter;
@property (nonatomic, copy) NSDateFormatter *monthDayYearDateFormatter;

@end

@implementation XHPathTimeScroller

#pragma mark - Public Api

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    // 刚开始滚动
    // 1、检查滚动视图和徘徊的bar是否存在,如果不存在就需要去获取这些对象了
    if (!_tableView || !_scrollBar)
        [self _captureTableViewAndScrollBar];
    
    // 2、然后在保险的检查bar是否存在，因为bar是依赖TableView的，如果不存在，那就说明没有意思了
    if (!_scrollBar)
        return;
    
    // 3、需要判断是否只有头部没有任何一个cell存在
    BOOL headTimeOnly = [self _headTimeOnly];
    
    // 4、设置自身的frmae
    CGRect selfFrame = self.frame;
    CGRect scrollBarFrame = _scrollBar.frame;
    self.frame = CGRectIntegral(CGRectMake(headTimeOnly ? -5 : (CGRectGetWidth(selfFrame) * -1.0f),
                                           headTimeOnly ? [self _getAdpterHiegth] : (CGRectGetHeight(scrollBarFrame) / 2.0f) - (CGRectGetHeight(selfFrame) / 2.0f),
                                           CGRectGetWidth(selfFrame),
                                           CGRectGetHeight(selfFrame)));

    // 5、这里是体验的开始，add上去的动画方式
    if (headTimeOnly) {
        [_tableView.superview addSubview:self];
        [UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState  animations:^{
            
            self.alpha = 1.0f;
            self.transform = CGAffineTransformIdentity;
            
        } completion:nil];
    } else {
        [_scrollBar addSubview:self];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 1、检查滚动视图和scrollBar是否存在
    if (!_tableView || !_scrollBar)
        [self _captureTableViewAndScrollBar];
    // 2、检查当获取到scrollBar的时候，保存的tableView的frame
    [self _checkChanges];
    
    // 3、再次保险的判断一下
    if (!_scrollBar)
        return;
    
    // 4、需要判断是否只有头部没有任何一个cell存在
    BOOL headTimeOnly = [self _headTimeOnly];
    
    // 5、设置自身的frmae
    CGRect selfFrame = self.frame;
    CGRect scrollBarFrame = _scrollBar.frame;
    self.frame = CGRectMake(headTimeOnly ? -5 : (CGRectGetWidth(selfFrame) * -1.0f),
                            [self _headTimeOnly] ? [self _getAdpterHiegth] : (CGRectGetHeight(scrollBarFrame) / 2.0f) - (CGRectGetHeight(selfFrame) / 2.0f),
                            CGRectGetWidth(selfFrame),
                            CGRectGetHeight(_backgroundImageView.frame));
    
    // 6、根据自身的中间的point，获取对应的cell
    CGPoint point = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
    point = [_scrollBar convertPoint:point toView:_tableView];
    UITableViewCell *cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]];
    
    // 7、获取tableView的tableHeaderView
    UIView *tableHeaderView = _tableView.tableHeaderView;

    // 8、判断cell是否存在
    if (cell) {
        // 更新显示时间
        [self _updateDisplayWithCell:cell];
        if (![self alpha]) {
            [UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
                [self setAlpha:1.0f];
            } completion:nil];
        }
    } else if (tableHeaderView) {
        // 9、判断tableHeaderView是否存在
        // 更新显示时间
        [self _updateDisplayWithTableHaderView:tableHeaderView];
        if (![self alpha]) {
            [UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
                [self setAlpha:1.0f];
            } completion:nil];
        }
    } else {
        if ([self alpha]) {
            [UIView animateWithDuration:0.2f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^{
                [self setAlpha:0.0f];
            } completion:nil];
        }
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    // 结束滚动
    // 为什么会有这样的判断呢？因为如果手指一直滑动离开滑动离开，但是tableView没有停止，所以需要在真正停止的时候才进行下一步操作
    if (scrollView.dragging || scrollView.decelerating || scrollView.tracking)
        return;
    
    // 1、我们需要检查徘徊的bar是否存在,不存在的话，走下去也是无意义的
    if (!_scrollBar)
        return;
    
    // 2、慢慢的消失，这就是体验了
    [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState  animations:^{
        
        self.alpha = 0.0f;
        self.transform = CGAffineTransformMakeTranslation(10.0f, 0.0f);
        
    } completion:nil];
}

#pragma mark - Previte

#pragma mark - adp hple method

- (CGFloat)_getAdpterHiegth {
    CGFloat headViewHeight = 0;
    UIViewController *viewController = (UIViewController *)self.delegate;
    if (viewController.navigationController) {
        CGFloat padding = 15;
        if ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7.0) {
            BOOL isRectEdgeNone = viewController.edgesForExtendedLayout == UIRectEdgeNone;
            headViewHeight = (isRectEdgeNone ? 0 : 64) + padding;
        } else {
            headViewHeight = padding;
        }
    }
    return headViewHeight;
}

- (BOOL)_headTimeOnly {
    if (!_tableView)
        return NO;
    
    BOOL isHeadTime = YES;
    NSArray *visibleCells = _tableView.visibleCells;
    if (visibleCells.count) {
        isHeadTime = NO;
    }
    return isHeadTime;
}

#pragma mark - display date for UI help method

- (void)_updateDisplayWithTableHaderView:(UIView *)tableHeaderView {
    NSDate *date = [NSDate new];
    [self _updateDisplayWithDate:date];
}

- (void)_updateDisplayWithCell:(UITableViewCell *)cell {
    NSDate *date = [self.delegate pathTimeScroller:self dateForCell:cell];
    [self _updateDisplayWithDate:date];
}

- (void)_updateDisplayWithDate:(NSDate *)date {
    if (!date || [date isEqualToDate:_lastDate]) {
        return;
    }
    if (!_lastDate) {
        _lastDate = [NSDate date];
    }
    NSDate *today = [NSDate date];
    
    NSDateComponents *dateComponents = [self.calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekOfYearCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:date];
    NSDateComponents *todayComponents = [self.calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekOfYearCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:today];
    NSDateComponents *lastDateComponents = [self.calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSWeekOfYearCalendarUnit | NSWeekCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:_lastDate];
    
    _timeLabel.text = [self.timeDateFormatter stringFromDate:date];
    
    CGFloat currentHourAngle = 0.5f * ((lastDateComponents.hour * 60.0f) + lastDateComponents.minute);
    CGFloat newHourAngle = 0.5f * ((dateComponents.hour * 60.0f) + dateComponents.minute);
    CGFloat currentMinuteAngle = 6.0f * lastDateComponents.minute;
    CGFloat newMinuteAngle = 6.0f * dateComponents.minute;
    
    currentHourAngle = currentHourAngle > 360 ? currentHourAngle - 360 : currentHourAngle;
    newHourAngle = newHourAngle > 360 ? newHourAngle - 360 : newHourAngle;
    currentMinuteAngle = currentMinuteAngle > 360 ? currentMinuteAngle - 360 : currentMinuteAngle;
    newMinuteAngle = newMinuteAngle > 360 ? newMinuteAngle - 360 : newMinuteAngle;
    
    CGFloat hourPartOne;
    CGFloat hourPartTwo;
    CGFloat hourPartThree;
    CGFloat hourPartFour;
    
    CGFloat minutePartOne;
    CGFloat minutePartTwo;
    CGFloat minutePartThree;
    CGFloat minutePartFour;
    
    if (newHourAngle > currentHourAngle && [date timeIntervalSinceDate:_lastDate] > 0) {
        CGFloat diff = newHourAngle - currentHourAngle;
        CGFloat part = diff / 4.0f;
        hourPartOne = currentHourAngle + part;
        hourPartTwo = hourPartOne + part;
        hourPartThree = hourPartTwo + part;
        hourPartFour = hourPartThree + part;
    } else if (newHourAngle < currentHourAngle && [date timeIntervalSinceDate:_lastDate] > 0) {
        CGFloat diff = (360 - currentHourAngle) + newHourAngle;
        CGFloat part = diff / 4.0f;
        hourPartOne = currentHourAngle + part;
        hourPartTwo = hourPartOne + part;
        hourPartThree = hourPartTwo + part;
        hourPartFour = hourPartThree + part;
    } else if (newHourAngle > currentHourAngle && [date timeIntervalSinceDate:_lastDate] < 0) {
        CGFloat diff = ((currentHourAngle) * -1.0f) - (360 - newHourAngle);
        CGFloat part = diff / 4.0f;
        hourPartOne = currentHourAngle + part;
        hourPartTwo = hourPartOne + part;
        hourPartThree = hourPartTwo + part;
        hourPartFour = hourPartThree + part;
    } else if (newHourAngle < currentHourAngle && [date timeIntervalSinceDate:_lastDate] < 0) {
        CGFloat diff = currentHourAngle - newHourAngle;
        CGFloat part = diff / 4;
        hourPartOne = currentHourAngle - part;
        hourPartTwo = hourPartOne - part;
        hourPartThree = hourPartTwo - part;
        hourPartFour = hourPartThree - part;
    } else {
        hourPartOne = hourPartTwo = hourPartThree = hourPartFour = currentHourAngle;
    }
    
    if (newMinuteAngle > currentMinuteAngle && [date timeIntervalSinceDate:_lastDate] > 0) {
        CGFloat diff = newMinuteAngle - currentMinuteAngle;
        CGFloat part = diff / 4.0f;
        minutePartOne = currentMinuteAngle + part;
        minutePartTwo = minutePartOne + part;
        minutePartThree = minutePartTwo + part;
        minutePartFour = minutePartThree + part;
    } else if (newMinuteAngle < currentMinuteAngle && [date timeIntervalSinceDate:_lastDate] > 0) {
        CGFloat diff = (360 - currentMinuteAngle) + newMinuteAngle;
        CGFloat part = diff / 4.0f;
        minutePartOne = currentMinuteAngle + part;
        minutePartTwo = minutePartOne + part;
        minutePartThree = minutePartTwo + part;
        minutePartFour = minutePartThree + part;
    } else if (newMinuteAngle > currentMinuteAngle && [date timeIntervalSinceDate:_lastDate] < 0) {
        CGFloat diff = ((currentMinuteAngle) * -1.0f) - (360 - newMinuteAngle);
        CGFloat part = diff / 4.0f;
        minutePartOne = currentMinuteAngle + part;
        minutePartTwo = minutePartOne + part;
        minutePartThree = minutePartTwo + part;
        minutePartFour = minutePartThree + part;
    } else if (newMinuteAngle < currentMinuteAngle && [date timeIntervalSinceDate:_lastDate] < 0) {
        CGFloat diff = currentMinuteAngle - newMinuteAngle;
        CGFloat part = diff / 4;
        minutePartOne = currentMinuteAngle - part;
        minutePartTwo = minutePartOne - part;
        minutePartThree = minutePartTwo - part;
        minutePartFour = minutePartThree - part;
    } else {
        minutePartOne = minutePartTwo = minutePartThree = minutePartFour = currentMinuteAngle;
    }
    
    [UIView animateWithDuration:0.075f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseIn animations:^{
        
        _hourHand.transform =  CGAffineTransformMakeRotation(hourPartOne * (M_PI / 180.0f));
        _minuteHand.transform =  CGAffineTransformMakeRotation(minutePartOne * (M_PI / 180.0f));
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.075f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
            
            _hourHand.transform =  CGAffineTransformMakeRotation(hourPartTwo * (M_PI / 180.0f));
            _minuteHand.transform =  CGAffineTransformMakeRotation(minutePartTwo * (M_PI / 180.0f));
            
        } completion:^(BOOL finished) {
            
            [UIView animateWithDuration:0.075f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear animations:^{
                
                _hourHand.transform =  CGAffineTransformMakeRotation(hourPartThree * (M_PI / 180.0f));
                _minuteHand.transform =  CGAffineTransformMakeRotation(minutePartThree * (M_PI / 180.0f));
                
            } completion:^(BOOL finished) {
                
                [UIView animateWithDuration:0.075f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut animations:^{
                    
                    _hourHand.transform =  CGAffineTransformMakeRotation(hourPartFour * (M_PI / 180.0f));
                    _minuteHand.transform =  CGAffineTransformMakeRotation(minutePartFour * (M_PI / 180.0f));
                    
                } completion:nil];
                
            }];
            
        }];
        
    }];
    
    _lastDate = date;
    
    CGRect backgroundFrame;
    CGRect timeLabelFrame;
    CGRect dateLabelFrame = _dateLabel.frame;
    NSString *dateLabelString;
    NSString *timeLabelString = _timeLabel.text;
    CGFloat dateLabelAlpha;
    
    if (dateComponents.year == todayComponents.year && dateComponents.month == todayComponents.month && dateComponents.day == todayComponents.day) {
        dateLabelString = @"";
        
        backgroundFrame = CGRectMake(CGRectGetWidth(self.frame) - 80.0f, 0.0f, 80.0f, CGRectGetHeight(self.frame));
        timeLabelFrame = CGRectMake(30.0f, 4.0f, 100.0f, 20.0f);
        dateLabelAlpha = 0.0f;
    } else if ((dateComponents.year == todayComponents.year) && (dateComponents.month == todayComponents.month) && (dateComponents.day == todayComponents.day - 1)) {
        timeLabelFrame = CGRectMake(30.0f, 4.0f, 100.0f, 10.0f);
        
        dateLabelString = @"Yesterday";
        dateLabelAlpha = 1.0f;
        backgroundFrame = CGRectMake(CGRectGetWidth(self.frame) - 85.0f, 0.0f, 85.0f, CGRectGetHeight(self.frame));
    } else if ((dateComponents.year == todayComponents.year) && (dateComponents.weekOfYear == todayComponents.weekOfYear)) {
        timeLabelFrame = CGRectMake(30.0f, 4.0f, 100.0f, 10.0f);
        dateLabelString = [self.dayOfWeekDateFormatter stringFromDate:date];
        dateLabelAlpha = 1.0f;
        
        CGFloat width = 0.0f;
        if ([dateLabelString sizeWithFont:_dateLabel.font].width < 50) {
            width = 85.0f;
        } else {
            width = 95.0f;
        }
        
        backgroundFrame = CGRectMake(CGRectGetWidth(self.frame) - width, 0.0f, width, CGRectGetHeight(self.frame));
    } else if (dateComponents.year == todayComponents.year) {
        timeLabelFrame = CGRectMake(30.0f, 4.0f, 100.0f, 10.0f);
        
        dateLabelString = [self.monthDayDateFormatter stringFromDate:date];
        dateLabelAlpha = 1.0f;
        
        CGFloat width = [dateLabelString sizeWithFont:_dateLabel.font].width + 50.0f;
        
        backgroundFrame = CGRectMake(CGRectGetWidth(self.frame) - width, 0.0f, width, CGRectGetHeight(self.frame));
    } else {
        timeLabelFrame = CGRectMake(30.0f, 4.0f, 100.0f, 10.0f);
        dateLabelString = [self.monthDayYearDateFormatter stringFromDate:date];
        dateLabelAlpha = 1.0f;
        
        CGFloat width = [dateLabelString sizeWithFont:_dateLabel.font].width + 50.0f;
        
        backgroundFrame = CGRectMake(CGRectGetWidth(self.frame) - width, 0.0f, width, CGRectGetHeight(self.frame));
    }

    [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowAnimatedContent animations:^{
        
        _timeLabel.frame = timeLabelFrame;
        _dateLabel.frame = dateLabelFrame;
        _dateLabel.alpha = dateLabelAlpha;
        _timeLabel.text = timeLabelString;
        _dateLabel.text = dateLabelString;
        _backgroundImageView.frame = backgroundFrame;
        
    } completion:nil];
}

#pragma mark - scrolling help method

- (void)_invalidate {
    _tableView = nil;
    _scrollBar = nil;
    [self removeFromSuperview];
}


- (void)_checkChanges {
    if (!_tableView ||
        _savedTableViewSize.height != _tableView.frame.size.height ||
        _savedTableViewSize.width != _tableView.frame.size.width) {
        [self _invalidate];
    }
}

- (void)_captureTableViewAndScrollBar {
    // 1、先获取滚动对象，这就是适配器设计模式的好处了，其实在别的地方也有用到，比如一个横向的UIScrollView里面嵌套3个UITableView的重用机制一样
    _tableView = [self.delegate tableViewForPathTimeScroller:self];
    
    // 2、设置frame
    self.frame = CGRectMake(CGRectGetWidth(self.frame) - 10.0f, 0.0f, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
    
    // 3、找到滚动视图的scrollBar,主要是把自己要显示的东西add到tableView别处，而不是直接add在tableView上，如果直接add在tableView上，你们想想就知道有什么问题了
    NSArray *tableViewSubviews = _tableView.subviews;
    for (id subview in tableViewSubviews) {
        if ([subview isKindOfClass:[UIImageView class]]) {
            UIImageView *imageView = (UIImageView *)subview;
            
            if (imageView.frame.size.width == 7.0f || imageView.frame.size.width == 5.0f || imageView.frame.size.width == 3.5f || imageView.frame.size.width == 3.0f) {
                imageView.clipsToBounds = NO;
                [imageView addSubview:self];
                _scrollBar = imageView;
                _savedTableViewSize = _tableView.frame.size;
            }
        }
    }
}

#pragma mark - dateFormatter help method

- (void)_createFormatters {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setCalendar:self.calendar];
    [dateFormatter setTimeZone:self.calendar.timeZone];
    [dateFormatter setDateFormat:@"h:mm a"];
    self.timeDateFormatter = dateFormatter;
    
    dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setCalendar:self.calendar];
    [dateFormatter setTimeZone:self.calendar.timeZone];
    dateFormatter.dateFormat = @"cccc";
    self.dayOfWeekDateFormatter = dateFormatter;
    
    dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setCalendar:self.calendar];
    [dateFormatter setTimeZone:self.calendar.timeZone];
    dateFormatter.dateFormat = @"MMMM d";
    self.monthDayDateFormatter = dateFormatter;
    
    dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setCalendar:self.calendar];
    [dateFormatter setTimeZone:self.calendar.timeZone];
    dateFormatter.dateFormat = @"MMMM d, yyyy";
    self.monthDayYearDateFormatter = dateFormatter;
}

#pragma mark - Propertys

- (void)setCalendar:(NSCalendar *)calendar {
    if (_calendar == calendar)
        return;
    
    // 如果我们利用设置后某个历法后，就马上初始化Formatter，因为Formatter可以根据某个历法来进行初始化
    [self _createFormatters];
    
    _calendar = calendar;
}

#pragma mark - life cycle

- (void)_setup {
    // 1、用于解析用的历法
    self.calendar = [NSCalendar currentCalendar];
    
    // 2、设置一下自己的默认状态，因为一开始是隐藏的啦！
    self.frame = CGRectMake(0.0f, 0.0f, CGRectGetWidth(XHScreenMainBounds), _timeScrollBackgroundImage.size.height);
    self.alpha = 0.0f;
    self.transform = CGAffineTransformMakeTranslation(10.0f, 0.0f);
    
    // 3、把分析出来的控件add上去
    _backgroundImageView = [[UIImageView alloc] initWithImage:_timeScrollBackgroundImage];
    _backgroundImageView.frame = CGRectMake(CGRectGetWidth(self.frame) - 80.0f, 0.0f, 80.0f, CGRectGetHeight(self.frame));
    [self addSubview:_backgroundImageView];
    
    _handContainer = [[UIView alloc] initWithFrame:CGRectMake(5.0f, 4.0f, 20.0f, 20.0f)];
    [_backgroundImageView addSubview:_handContainer];
    
    _hourHand = [[UIView alloc] initWithFrame:CGRectMake(8.0f, 0.0f, 4.0f, 20.0f)];
    UIImageView *hourImageView = [[UIImageView alloc] initWithImage:_hourHandImage];
    [_hourHand addSubview:hourImageView];
    [_handContainer addSubview:_hourHand];
    
    _minuteHand = [[UIView alloc] initWithFrame:CGRectMake(8.0f, 0.0f, 4.0f, 20.0f)];
    UIImageView *minuteImageView = [[UIImageView alloc] initWithImage:_minuteHandImage];
    [_minuteHand addSubview:minuteImageView];
    [_handContainer addSubview:_minuteHand];
    
    
    _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 4.0f, 50.0f, 20.0f)];
    _timeLabel.textColor = [UIColor whiteColor];
    _timeLabel.shadowColor = [UIColor blackColor];
    _timeLabel.shadowOffset = CGSizeMake(-0.5f, -0.5f);
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:9.0f];
    _timeLabel.autoresizingMask = UIViewAutoresizingNone;
    [_backgroundImageView addSubview:_timeLabel];
    
    _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 9.0f, 100.0f, 20.0f)];
    _dateLabel.textColor = [UIColor colorWithRed:179.0f green:179.0f blue:179.0f alpha:0.60f];
    _dateLabel.shadowColor = [UIColor blackColor];
    _dateLabel.shadowOffset = CGSizeMake(-0.5f, -0.5f);
    _dateLabel.text = @"6:00 PM";
    _dateLabel.backgroundColor = [UIColor clearColor];
    _dateLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:9.0f];
    _dateLabel.alpha = 0.0f;
    [_backgroundImageView addSubview:_dateLabel];
}

- (instancetype)initWithDelegate:(id<XHPathTimeScrollerDelegate>)delegate {
    UIImage *timeScrollerBackgroundImage = [UIImage imageNamed:@""];
    return [self initWithDelegate:delegate timeScrollerBackgroundImage:timeScrollerBackgroundImage];
}

- (instancetype)initWithDelegate:(id<XHPathTimeScrollerDelegate>)delegate timeScrollerBackgroundImage:(UIImage *)timeScrollerBackgroundImage {
    UIImage *hourHandImage = [UIImage imageNamed:@""];
    UIImage *minuteHandImage = [UIImage imageNamed:@""];
    return [self initWithDelegate:delegate timeScrollerBackgroundImage:timeScrollerBackgroundImage hourHandImage:hourHandImage minuteHandImage:minuteHandImage];
}

- (instancetype)initWithDelegate:(id<XHPathTimeScrollerDelegate>)delegate timeScrollerBackgroundImage:(UIImage *)timeScrollerBackgroundImage hourHandImage:(UIImage *)hourHandImage minuteHandImage:(UIImage *)minuteHandImage {
    self = [super init];
    if (self) {
        [self _setup];
    }
    return self;
}

@end
